﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using T_Person.APi.Applation.CommandHandlers.PersonnelHandlers;
using T_Person.APi.Applation.Commands.PersonnelCommand;

namespace T_Person.APi.Controllers
{
    /// <summary>
    /// 人事管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PersonnelController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="mediator"></param>
        public PersonnelController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 人事添加(转正,离职,入职)
        /// </summary>
        /// <param name="personnelAddHandlers"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int>AddPersonnel(PersonnelAddHandlers personnelAddHandlers)
        {
            return await mediator.Send(personnelAddHandlers);
        }
        /// <summary>
        /// 逻辑单删除方法
        /// </summary>
        /// <param name="personnelsDeleteHandler"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> DeletePersonnel([FromQuery]PersonnelsDeleteHandler personnelsDeleteHandler)
        {
            return await mediator.Send(personnelsDeleteHandler);
        }
        /// <summary>
        /// 批量逻辑删除
        /// </summary>
        /// <param name="personnelDeleteListCommand"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> DeleteListPersonnel([FromQuery]PersonnelDeleteListCommand personnelDeleteListCommand)
        {
            return await mediator.Send(personnelDeleteListCommand);
        }
        /// <summary>
        /// 更新人事表
        /// </summary>
        /// <param name="personnelUpdateHandlers"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int>UpdatePersonnels(PersonnelUpdateHandlers personnelUpdateHandlers)
        {
            return await mediator.Send(personnelUpdateHandlers);
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="personnelUpdateByidHandlers"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int>UpdateByidStatePersonnels(PersonnelUpdateByidHandlers personnelUpdateByidHandlers)
        {
            return await mediator.Send(personnelUpdateByidHandlers);
        }
    }
}
